<template>
  <el-dialog v-model="dialogVisible" title="修改魔学院" width="600" :before-close="handleClose">
    <el-select v-model="tags" placeholder="请选择课程标签" multiple filterable>
      <el-option v-for="item in tableData" :key="item.value" :label="item.tagname" :value="item.tagid" />
    </el-select>
    <template #footer>
      <div class="dialog-footer">
        <el-button @click="handleClose">取 消</el-button>
        <el-button type="primary" @click="confirm" :loading="loading">
          确 认
        </el-button>
      </div>
    </template>
  </el-dialog>
</template>

<script setup lang="ts">
import useCounterStore from "@/store/counter";
const counter = useCounterStore();
const instance = getCurrentInstance();
const { proxy } = getCurrentInstance();
const emit = defineEmits(["fatherMethod"]);

let dialogVisible = ref(false);
let tags = ref([]);
let tableData = ref([]);
let loading = ref(false);
let list = [];

async function open(selectData) {
  list = proxy.$utils.deepcopy(selectData);
  console.log("list", list);
  tableData.value = await proxy.$apis.moxueyuanTags({ type: "list" });
  dialogVisible.value = true;
}

async function confirm() {
  try {
    loading.value = true;
    for (let index = 0; index < list.length; index++) {
      const element = list[index];
      let data = {
        userId: element.userId,
        mobile: element.mobile ? element.mobile : element.order_Info.mobile,
        name: element.userName
          ? element.userName
          : element.approvalContent.model.name,
        tag: tags.value,
      };
      await proxy.$apis.orderAction({ type: "editOrderMoxueyuan", data });
    }
    proxy.$utils.showToast("修改成功");
    handleClose();
  } catch (error) {
  } finally {
    loading.value = false;
  }
}

function handleClose() {
  tags.value = [];
  emit("fatherMethod", "init"); //列表重新加载
  dialogVisible.value = false;
}

defineExpose({ open });
</script>



<style lang="scss" scoped>
</style>

